package com.hillstone.hsm.swtool.shellp.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hillstone.hsm.swtool.shellp.common.AjaxResult;
import com.hillstone.hsm.swtool.shellp.service.passwd.IPasswdService;

@Controller
@RequestMapping("/passwd")
public class ShellPasswdController {
	
	@Autowired
	private IPasswdService passwdService;
	
	@ResponseBody
	@RequestMapping(value = "/shell", method = RequestMethod.GET)
	public AjaxResult getShellPasswd(@RequestParam String sn,
				@RequestParam(required = false) String date) {
		if(date == null || "".equals(date)) {
			date = "20180331";
		}
		String passwd =  passwdService.getShellPasswd(sn, date);
		return AjaxResult.getInstance(passwd);
	}
	
	@ResponseBody
	@RequestMapping(value = "/root", method = RequestMethod.GET)
	public AjaxResult getRootPasswd(@RequestParam String sn) {
		String passwd =  passwdService.getRootPasswd(sn);
		return AjaxResult.getInstance(passwd);
	}
}
